cmake_minimum_required(VERSION 3.2)

project("cmg")

cmake_policy(SET CMP0077 NEW)

set(CMAKE_C_COMPILER clang-11)
set(CMAKE_CXX_COMPILER clang++-11)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED True)

set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)

# find LLVM and Clang package
find_package(LLVM 11 EXACT REQUIRED)
# find_package(Clang REQUIRED PATHS /usr/lib/cmake/clang-11)

# add LLVM_DIR to cmake module searching path
list(APPEND CMAKE_MODULE_PATH ${LLVM_DIR})

# import LLVM configuration for some macro, function and others
include(AddLLVM)
include(HandleLLVMOptions)

message(STATUS "llvm version: ${LLVM_VERSION}")
# message(STATUS "clang version: ${CLANG_VERSION}"

# export runtime output to /build/bin
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
# export library output to /build/lib
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

# add LLVM_DEFINITIONS to compile commands of all targets
add_definitions(${LLVM_DEFINITIONS})

# add header file searching paths of clang and llvm to all targets
include_directories(
    ${LLVM_INCLUDE_DIRS}
    ${CLANG_INCLUDE_DIRS}
    )

# add library searching paths of llvm
link_directories(${LLVM_LIBRARY_DIRS})

set(LLVM_LINK_COMPONENTS
    Option
    Support
    X86AsmParser
    X86Desc
    X86Info
    )

include(./Clang.cmake)

add_subdirectory(./tools)

install(TARGETS cmg-ide DESTINATION bin)
install(TARGETS cmg-ffe DESTINATION bin)
install(TARGETS CmgDudePass DESTINATION lib)